<?php
require_once('database.inc.php');
require_once('functions.inc.php');

$dbh = connect_db("dbm");
$lastupdate = getLastUpdate();

$page = 0;
$n = 0;
if (isset($_GET['n']) && is_numeric($_GET['n'])) {
	$n = $_GET['n'];
	$page = 25 * $_GET['n'];
}

if (!$query = mysql_query("SELECT loginname, s.userid, t.leagueid, since
FROM `supporters` s, `teams_$lastupdate` t
WHERE s.userid = t.userid
ORDER BY since DESC
LIMIT $page, 25", $dbh)) die (mysql_error());

$prevsince = "";
echo "<table>\n<tr><th>#<th>Supporter<th>ID<th>Since\n";
while ($row = mysql_fetch_array($query)) {
	$page++;
	echo "<tr><td>";
	if ($row['since'] !== $prevsince) echo "$page.";
	echo "<td><img src=\"flags/{$row['leagueid']}flag.gif\" border=\"1\" /> {$row['loginname']}<td>{$row['userid']}<td>{$row['since']}\n";
	$prevsince = $row['since'];
}
echo "</table>\n";
if ($n > 0) echo "<a href=\"supporters.php?n=" . ($n-1) . "\">prev</a> ";
else echo "prev ";
if (mysql_num_rows($query) == 25) echo "<a href=\"supporters.php?n=" . ($n+1) . "\">next</a>\n";
else echo "next\n";

?>
